//
//  UIBarButtonItem+GKExtension.m
//  GKExtension
//
//  Created by 花菜ChrisCai on 2014/5/22.
//  Copyright © 2014年 Chris. All rights reserved.
//

#import "UIBarButtonItem+GKExtension.h"

@implementation UIBarButtonItem (GKExtension)
#pragma mark -
#pragma mark - 高亮状态
+ (instancetype)gk_itemWithImage:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action;
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setBackgroundImage:highImage forState:UIControlStateHighlighted];
    [button sizeToFit];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 解决包装成UIButtonItem 点击范围过大的bug
    UIView *btnView = [[UIView alloc]initWithFrame:button.bounds];
    [btnView addSubview:button];
    return [[self alloc] initWithCustomView:btnView];
}

#pragma mark -
#pragma mark - 选中状态
+ (instancetype)gk_itemWithImage:(UIImage *)image selectedImage:(UIImage *)selectedImage target:(id)target action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setBackgroundImage:selectedImage forState:UIControlStateSelected];
    [button sizeToFit];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 解决包装成UIButtonItem 点击范围过大的bug
    UIView *btnView = [[UIView alloc]initWithFrame:button.bounds];
    [btnView addSubview:button];
    return [[self alloc] initWithCustomView:btnView];
}

#pragma mark -
#pragma mark - 带标题的
+ (instancetype)gk_itemWithTitle:(NSString *)title currentColor:(UIColor *)currentColor highColor:(UIColor *)highColor image:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action;
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:currentColor forState:UIControlStateNormal];
    [button setTitleColor:highColor forState:UIControlStateHighlighted];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:highImage forState:UIControlStateHighlighted];
    [button sizeToFit];
    button.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 解决包装成UIButtonItem 点击范围过大的bug
    UIView *btnView = [[UIView alloc]initWithFrame:button.bounds];
    [btnView addSubview:button];
    return [[self alloc] initWithCustomView:btnView];
}



@end
